<?php
/**
 * 处理性格的主题，每个性格为一个主题，
 * 可以理解为一个性格一个订阅
 * @author Administrator
 * @create 2013-4-19 11:08:59
 */
class Subscribe_Push_Subject_Main extends Subscribe_Push_Subject_Abstract
{
	public function dealTrigger()
	{
		$criteriaObj = new Subscribe_Push_Criteria();
		$stockObj = new Subscribe_Push_Stock();
		for ($style = 0; $style < 10; $style++) {
			$allStock = $stockObj->getAllAlertStock($style);
			foreach ($allStock as $stock) {
				$currentPrice = $stockObj->getCurrentPrice($stock['code']);
				$result = $criteriaObj->isInRange($currentPrice, $stock);
				if ($result['isInRange']) {
					$this->notifyObserver($style, $result);
				}
			}
		}
	}
	
	public function test($currPrice, $code)
	{
		$criteriaObj = new Subscribe_Push_Criteria();
		$stockObj = new Subscribe_Push_Stock();
		for ($style = 0; $style < 10; $style++) {
			$allStock = $stockObj->getAllAlertStock($style);
			foreach ($allStock as $stock) {
				if ($stock['code'] != $code) {
					$currentPrice = $stockObj->getCurrentPrice($stock['code']);
				} else {
					$currentPrice = $currPrice;
				}
				$result = $criteriaObj->isInRange($currentPrice, $stock);
				if ($result['isInRange']) {
					$this->notifyObserver($style, $result);
				}
			}
		}
	}
}